package com.djakapm.swing.common;

import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;

import com.djakapm.swing.container.BorderPanel;
import com.djakapm.swing.container.FlowPanel;
import com.djakapm.swing.container.GridPanel;

/**
 * Helper class for creating top level container such as JFrame or JWindow.
 */
public class ContainerFactory {
    public static final int FRAME_DEFAULT_WIDTH = 640;
    public static final int FRAME_DEFAULT_HEIGHT = 320;


    /**
     * Create new JFrame object with default settings.
     *
     * @return new JFrame object.
     */
    public static JFrame newFrame() {
        return newFrame(FRAME_DEFAULT_WIDTH, FRAME_DEFAULT_HEIGHT);
    }

    /**
     * Create default JFrame with title specified.
     *
     * @param title set new JFrame object title property.
     * @return new JFrame object.
     */
    public static JFrame newFrame(String title) {
        return newFrame(title, FRAME_DEFAULT_WIDTH, FRAME_DEFAULT_HEIGHT);
    }

    /**
     * Create new JFrame with specific size.
     *
     * @param width  the width of the new JFrame object.
     * @param height the height of the new JFrame object.
     * @return new JFrame object.
     */
    public static JFrame newFrame(int width, int height) {
        return newFrame(null, width, height);
    }

    /**
     * Create new JFrame with specific size with title.
     *
     * @param title  title set new JFrame object title property.
     * @param width  the width of the new JFrame object.
     * @param height the height of the new JFrame object.
     * @return new JFrame object.
     */
    public static JFrame newFrame(String title, int width, int height) {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        if (title != null && !"".equalsIgnoreCase(title)) {
            frame.setTitle(title);
        }
        frame.setSize(width, height);
        return frame;
    }

    /**
     * Create default JPanel.
     *
     * @return new JPanel object.
     */
    public static JPanel newPanel() {
        return new JPanel();
    }

    /**
     * Create a panel using grid layout as its layout manager.
     * @return new JPanel object
     */
    public static GridPanel newGridLayoutedPanel(){
        return new GridPanel();
    }

    /**
     * Create a panel using grid layout as its layout manager.
     * With user define number of rows and columns.
     * @param rows Number of rows
     * @param cols Number of columns
     * @return new JPanel object
     */
    public static GridPanel newGridLayoutedPanel(int rows,int cols){
        return new GridPanel(rows,cols);
    }

    /**
     * Create a panel using grid layout as its layout manager.
     * With user define number of rows and columns also user define horizontal and vertical gap.
     * @param rows Number of rows
     * @param cols Number of columns
     * @param hgap Horizontal gap between rows
     * @param vgap Vertical gap between columns
     * @return new JPanel object
     */
    public static GridPanel newGridLayoutedPanel(int rows,int cols,int hgap,int vgap){
        return new GridPanel(rows,cols,hgap,vgap);
    }

    /**
     * Create a panel using border layout as its layout manager.
     *
     * @return new BorderPanel object;
     */
    public static BorderPanel newBorderLayoutedPanel() {
        return new BorderPanel();
    }

    /**
     * Create a panel using flow layout as its layout manager.
     *
     * @return new FlowPanel object;
     */
    public static FlowPanel newFlowLayoutedPanel() {
        return new FlowPanel();
    }

    /**
     * Create a panel using flow left layout as its layout manager.
     *
     * @return new FlowPanel object;
     */
    public static FlowPanel newFlowLeftLayoutedPanel() {
        return new FlowPanel(FlowLayout.LEFT);
    }

    /**
     * Create a panel using flow right layout as its layout manager.
     *
     * @return new FlowPanel object;
     */
    public static FlowPanel newFlowRightLayoutedPanel() {
        return new FlowPanel(FlowLayout.RIGHT);
    }

    /**
     * Create a panel using flow leading layout as its layout manager.
     *
     * @return new FlowPanel object;
     */

    public static FlowPanel newFlowLeadingLayoutedPanel() {
        return new FlowPanel(FlowLayout.LEADING);
    }

    /**
     * Create a panel using flow center layout as its layout manager.
     *
     * @return new FlowPanel object;
     */

    public static FlowPanel newFlowCenterLayoutedPanel() {
        return new FlowPanel(FlowLayout.CENTER);
    }

    /**
     * Create a panel using flow trailing layout as its layout manager.
     *
     * @return new FlowPanel object;
     */
	public static JPanel newFlowTrailingLayoutedPanel() {
		return new FlowPanel(FlowLayout.TRAILING);
	}
	
	
	
	
}
